package com.hx.vending.controller;

import com.hx.vending.annotation.Authorization;
import com.hx.vending.annotation.CurrentUserId;
import com.hx.vending.bean.Problem;
import com.hx.vending.service.IProblemService;
import com.hx.vending.util.DateUtil;
import com.hx.vending.util.Msg;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

/**
 * Created by Administrator on 2019/1/25.
 */
@Controller
@RequestMapping("/problem")
public class ProblemController {

    @Autowired
    private IProblemService problemService;
    /**
     * 提交问题
     * @param problem
     * @return
     */
    @ResponseBody
    @RequestMapping("/addProblem")
    public Msg insertProblem(@RequestBody Problem problem){
        return problemService.insertProblem(problem);
    }

    /**
     * 查询问题
     * @return
     */
    @ResponseBody
    @RequestMapping("/selectProblem")
    public Msg selectProblem(Integer userId){
        try {
            List<Problem> problemList = problemService.selectByCondition(userId);
            return Msg.success().add("problemList",problemList);
        }catch (Exception e){
            return Msg.fail();
        }

    }
}